package com.xgkj.ffmpegandroiddemo;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.File;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    private FFmpegUtils fFmpegUtils;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = (TextView) findViewById(R.id.sample_text);
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(this);
        fFmpegUtils = new FFmpegUtils();

        // tv.setText(fFmpegUtils.avcodecInfo());
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn:

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            String s = Environment.getExternalStorageDirectory().toString();
                            String s1 = s + File.separator + "qian.mp4";

                            String[] commands = new String[12];
                            commands[0] = "ffmpeg";
                            commands[1] = "-i";
                            commands[2] = s + File.separator + "qian.mp4";
                            commands[3] = "-b";
                            commands[4] = "1024k";
                            commands[5] = "-r";
                            commands[6] = "25";
                            commands[7] = "-s";
                            commands[8] = "720x480";
                            commands[9] = "-aspect";
                            commands[10] = "16:9";
                            commands[11] = s + File.separator + "ren.mp4";
                            int videotranscode = fFmpegUtils.videotranscode(commands.length, commands);
                            Log.e("videotranscode", "onClick: " + videotranscode);
                        } catch (Exception e) {
                            Log.e("fFmpegUtils", "onClick: " + e.toString());
                        }
                    }
                };
                ThreadPoolUtils.execute(runnable);
                break;
        }
    }
}
